<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN" "http://www.w3.org/TR/REC-html40/strict.dtd">
<html><head><meta name="qrichtext" content="1" /><meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /><style type="text/css">
p, li { white-space: pre-wrap; }
</style></head><body style=" font-family:'MS Shell Dlg 2'; font-size:10pt; font-weight:400; font-style:normal;">
<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-family:'inherit'; font-size:xx-large; color:#222222;">Как печатать timedelta без долей секунд</span></p>
<p style=" margin-top:7px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; line-height:1.5%;"><span style=" font-family:'-apple-system,system-ui,BlinkMacSystemFont,Segoe UI,Helvetica,Arial,sans-serif,Apple Color Emoji,Segoe UI Emoji,Segoe UI Symbol'; font-size:17px; color:#000000;">21.06.2023 от </span><a href="https://qaa-engineer.ru/author/chatgpt/"><span style=" font-family:'-apple-system,system-ui,BlinkMacSystemFont,Segoe UI,Helvetica,Arial,sans-serif,Apple Color Emoji,Segoe UI Emoji,Segoe UI Symbol'; font-size:17px; text-decoration: underline; color:#000000;">ChatGPT</span></a></p>
<p style="-qt-paragraph-type:empty; margin-top:7px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; line-height:1.5%; font-family:'-apple-system,system-ui,BlinkMacSystemFont,Segoe UI,Helvetica,Arial,sans-serif,Apple Color Emoji,Segoe UI Emoji,Segoe UI Symbol'; font-size:17px; text-decoration: underline; color:#000000;"><br /></p>
<p style="-qt-paragraph-type:empty; margin-top:7px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; line-height:1.5%; font-family:'-apple-system,system-ui,BlinkMacSystemFont,Segoe UI,Helvetica,Arial,sans-serif,Apple Color Emoji,Segoe UI Emoji,Segoe UI Symbol'; font-size:17px; text-decoration: underline; color:#000000;"><br /></p>
<p style="-qt-paragraph-type:empty; margin-top:7px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; line-height:1.5%; font-family:'-apple-system,system-ui,BlinkMacSystemFont,Segoe UI,Helvetica,Arial,sans-serif,Apple Color Emoji,Segoe UI Emoji,Segoe UI Symbol'; font-size:17px; text-decoration: underline; color:#000000;"><br /></p>
<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><a href="https://qaa-engineer.ru/"><span style=" font-family:'-apple-system,system-ui,BlinkMacSystemFont,Segoe UI,Helvetica,Arial,sans-serif,Apple Color Emoji,Segoe UI Emoji,Segoe UI Symbol'; font-size:17px; text-decoration: underline; color:#000000;">qaa-engineer.ru</span></a><span style=" font-family:'-apple-system,system-ui,BlinkMacSystemFont,Segoe UI,Helvetica,Arial,sans-serif,Apple Color Emoji,Segoe UI Emoji,Segoe UI Symbol'; font-size:17px; color:#222222;"> &gt; </span><a href="https://qaa-engineer.ru/category/voprosy-i-otvety/"><span style=" font-family:'-apple-system,system-ui,BlinkMacSystemFont,Segoe UI,Helvetica,Arial,sans-serif,Apple Color Emoji,Segoe UI Emoji,Segoe UI Symbol'; font-size:17px; text-decoration: underline; color:#000000;">Вопросы и ответы</span></a><span style=" font-family:'-apple-system,system-ui,BlinkMacSystemFont,Segoe UI,Helvetica,Arial,sans-serif,Apple Color Emoji,Segoe UI Emoji,Segoe UI Symbol'; font-size:17px; color:#222222;"> &gt; Как печатать timedelta без долей секунд</span></p>
<p style=" margin-top:46px; margin-bottom:20px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-family:'-apple-system,system-ui,BlinkMacSystemFont,Segoe UI,Helvetica,Arial,sans-serif,Apple Color Emoji,Segoe UI Emoji,Segoe UI Symbol'; font-size:17px; color:#222222;">Часто при работе с временем в Python возникает необходимость вывести временной интервал в формате, который не содержит доли секунд. В стандартной библиотеке Python для работы с временем используется модуль datetime. В этой статье мы рассмотрим способы вывода интервала времени без долей секунд с помощью модуля datetime.</span></p>
<p style=" margin-top:0px; margin-bottom:20px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-family:'-apple-system,system-ui,BlinkMacSystemFont,Segoe UI,Helvetica,Arial,sans-serif,Apple Color Emoji,Segoe UI Emoji,Segoe UI Symbol'; font-size:17px; color:#222222;">Первый способ вывода интервала времени без долей секунд — это использование метода strftime() объекта timedelta. Метод strftime() принимает строку формата времени и возвращает строку, содержащую представление времени в соответствии с заданным форматом. В следующем примере мы создаем объект timedelta, содержащий временной интервал в 1000 секунд, и выводим его без долей секунд:</span></p>
<p style="-qt-paragraph-type:empty; margin-top:13px; margin-bottom:13px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; font-family:'-apple-system,system-ui,BlinkMacSystemFont,Segoe UI,Helvetica,Arial,sans-serif,Apple Color Emoji,Segoe UI Emoji,Segoe UI Symbol'; font-size:17px; color:#222222; background-color:#ffffff;"><br /></p>
<table border="0" style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px;" cellspacing="0" cellpadding="0">
<tr>
<td bgcolor="#ffffff" style=" padding-left:0; padding-right:0; padding-top:0; padding-bottom:0;">
<p align="right" style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:13px; -qt-block-indent:0; text-indent:0px; background-color:#ffffff;"><a name="highlighter_624213"></a><span style=" font-family:'Monaco,Consolas,Bitstream Vera Sans Mono,Courier New,Courier,monospace'; font-size:17px; color:#afafaf; background-color:#ffffff;">1</span></p>
<p align="right" style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:13px; -qt-block-indent:0; text-indent:0px; background-color:#ffffff;"><span style=" font-family:'Monaco,Consolas,Bitstream Vera Sans Mono,Courier New,Courier,monospace'; font-size:17px; color:#afafaf; background-color:#ffffff;">2</span></p>
<p align="right" style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:13px; -qt-block-indent:0; text-indent:0px; background-color:#ffffff;"><span style=" font-family:'Monaco,Consolas,Bitstream Vera Sans Mono,Courier New,Courier,monospace'; font-size:17px; color:#afafaf; background-color:#ffffff;">3</span></p>
<p align="right" style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:13px; -qt-block-indent:0; text-indent:0px; background-color:#ffffff;"><span style=" font-family:'Monaco,Consolas,Bitstream Vera Sans Mono,Courier New,Courier,monospace'; font-size:17px; color:#afafaf; background-color:#ffffff;">4</span></p></td>
<td bgcolor="#ffffff" style=" padding-left:0; padding-right:0; padding-top:0; padding-bottom:0;">
<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; background-color:#ffffff;"><span style=" font-family:'Monaco,Consolas,Bitstream Vera Sans Mono,Courier New,Courier,monospace'; font-size:17px; color:#000000;">import datetime</span></p>
<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; background-color:#ffffff;"><span style=" font-family:'Monaco,Consolas,Bitstream Vera Sans Mono,Courier New,Courier,monospace'; font-size:17px; color:#222222; background-color:#ffffff;"> </span></p>
<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; background-color:#ffffff;"><span style=" font-family:'Monaco,Consolas,Bitstream Vera Sans Mono,Courier New,Courier,monospace'; font-size:17px; color:#000000;">delta = datetime.timedelta(seconds=1000)</span></p>
<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; background-color:#ffffff;"><span style=" font-family:'Monaco,Consolas,Bitstream Vera Sans Mono,Courier New,Courier,monospace'; font-size:17px; color:#000000;">print(delta.strftime('%H:%M:%S'))</span></p></td></tr></table>
<p style=" margin-top:0px; margin-bottom:20px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-family:'-apple-system,system-ui,BlinkMacSystemFont,Segoe UI,Helvetica,Arial,sans-serif,Apple Color Emoji,Segoe UI Emoji,Segoe UI Symbol'; font-size:17px; color:#222222;">Результат выполнения кода будет следующим:</span></p>
<p style="-qt-paragraph-type:empty; margin-top:13px; margin-bottom:13px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; font-family:'-apple-system,system-ui,BlinkMacSystemFont,Segoe UI,Helvetica,Arial,sans-serif,Apple Color Emoji,Segoe UI Emoji,Segoe UI Symbol'; font-size:17px; color:#222222; background-color:#ffffff;"><br /></p>
<table border="0" style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px;" cellspacing="0" cellpadding="0">
<tr>
<td bgcolor="#ffffff" style=" padding-left:0; padding-right:0; padding-top:0; padding-bottom:0;">
<p align="right" style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:13px; -qt-block-indent:0; text-indent:0px; background-color:#ffffff;"><a name="highlighter_498206"></a><span style=" font-family:'Monaco,Consolas,Bitstream Vera Sans Mono,Courier New,Courier,monospace'; font-size:17px; color:#afafaf; background-color:#ffffff;">1</span></p></td>
<td bgcolor="#ffffff" style=" padding-left:0; padding-right:0; padding-top:0; padding-bottom:0;">
<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; background-color:#ffffff;"><span style=" font-family:'Monaco,Consolas,Bitstream Vera Sans Mono,Courier New,Courier,monospace'; font-size:17px; color:#000000;">00:16:40</span></p></td></tr></table>
<p style=" margin-top:0px; margin-bottom:20px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-family:'-apple-system,system-ui,BlinkMacSystemFont,Segoe UI,Helvetica,Arial,sans-serif,Apple Color Emoji,Segoe UI Emoji,Segoe UI Symbol'; font-size:17px; color:#222222;">Здесь мы использовали строку формата '%H:%M:%S', чтобы вывести только часы, минуты и секунды интервала.</span></p>
<p style=" margin-top:0px; margin-bottom:20px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-family:'-apple-system,system-ui,BlinkMacSystemFont,Segoe UI,Helvetica,Arial,sans-serif,Apple Color Emoji,Segoe UI Emoji,Segoe UI Symbol'; font-size:17px; color:#222222;">Единицы измерения времени, включенные в строку формата, могут варьироваться в зависимости от требуемого формата вывода. Например, чтобы вывести интервал в формате &quot;часы:минуты&quot;, мы можем использовать следующую строку формата:</span></p>
<p style="-qt-paragraph-type:empty; margin-top:13px; margin-bottom:13px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; font-family:'-apple-system,system-ui,BlinkMacSystemFont,Segoe UI,Helvetica,Arial,sans-serif,Apple Color Emoji,Segoe UI Emoji,Segoe UI Symbol'; font-size:17px; color:#222222; background-color:#ffffff;"><br /></p>
<table border="0" style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px;" cellspacing="0" cellpadding="0">
<tr>
<td bgcolor="#ffffff" style=" padding-left:0; padding-right:0; padding-top:0; padding-bottom:0;">
<p align="right" style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:13px; -qt-block-indent:0; text-indent:0px; background-color:#ffffff;"><a name="highlighter_810622"></a><span style=" font-family:'Monaco,Consolas,Bitstream Vera Sans Mono,Courier New,Courier,monospace'; font-size:17px; color:#afafaf; background-color:#ffffff;">1</span></p></td>
<td bgcolor="#ffffff" style=" padding-left:0; padding-right:0; padding-top:0; padding-bottom:0;">
<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; background-color:#ffffff;"><span style=" font-family:'Monaco,Consolas,Bitstream Vera Sans Mono,Courier New,Courier,monospace'; font-size:17px; color:#000000;">print(delta.strftime('%H:%M'))</span></p></td></tr></table>
<p style=" margin-top:0px; margin-bottom:20px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-family:'-apple-system,system-ui,BlinkMacSystemFont,Segoe UI,Helvetica,Arial,sans-serif,Apple Color Emoji,Segoe UI Emoji,Segoe UI Symbol'; font-size:17px; color:#222222;">Результат выполнения будет таким:</span></p>
<p style="-qt-paragraph-type:empty; margin-top:13px; margin-bottom:13px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; font-family:'-apple-system,system-ui,BlinkMacSystemFont,Segoe UI,Helvetica,Arial,sans-serif,Apple Color Emoji,Segoe UI Emoji,Segoe UI Symbol'; font-size:17px; color:#222222; background-color:#ffffff;"><br /></p>
<table border="0" style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px;" cellspacing="0" cellpadding="0">
<tr>
<td bgcolor="#ffffff" style=" padding-left:0; padding-right:0; padding-top:0; padding-bottom:0;">
<p align="right" style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:13px; -qt-block-indent:0; text-indent:0px; background-color:#ffffff;"><a name="highlighter_922106"></a><span style=" font-family:'Monaco,Consolas,Bitstream Vera Sans Mono,Courier New,Courier,monospace'; font-size:17px; color:#afafaf; background-color:#ffffff;">1</span></p></td>
<td bgcolor="#ffffff" style=" padding-left:0; padding-right:0; padding-top:0; padding-bottom:0;">
<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; background-color:#ffffff;"><span style=" font-family:'Monaco,Consolas,Bitstream Vera Sans Mono,Courier New,Courier,monospace'; font-size:17px; color:#000000;">00:16</span></p></td></tr></table>
<p style=" margin-top:0px; margin-bottom:20px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-family:'-apple-system,system-ui,BlinkMacSystemFont,Segoe UI,Helvetica,Arial,sans-serif,Apple Color Emoji,Segoe UI Emoji,Segoe UI Symbol'; font-size:17px; color:#222222;">Также можно добавить другие единицы измерения времени в строку формата, например, дни или месяцы:</span></p>
<p style="-qt-paragraph-type:empty; margin-top:13px; margin-bottom:13px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; font-family:'-apple-system,system-ui,BlinkMacSystemFont,Segoe UI,Helvetica,Arial,sans-serif,Apple Color Emoji,Segoe UI Emoji,Segoe UI Symbol'; font-size:17px; color:#222222; background-color:#ffffff;"><br /></p>
<table border="0" style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px;" cellspacing="0" cellpadding="0">
<tr>
<td bgcolor="#ffffff" style=" padding-left:0; padding-right:0; padding-top:0; padding-bottom:0;">
<p align="right" style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:13px; -qt-block-indent:0; text-indent:0px; background-color:#ffffff;"><a name="highlighter_741674"></a><span style=" font-family:'Monaco,Consolas,Bitstream Vera Sans Mono,Courier New,Courier,monospace'; font-size:17px; color:#afafaf; background-color:#ffffff;">1</span></p>
<p align="right" style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:13px; -qt-block-indent:0; text-indent:0px; background-color:#ffffff;"><span style=" font-family:'Monaco,Consolas,Bitstream Vera Sans Mono,Courier New,Courier,monospace'; font-size:17px; color:#afafaf; background-color:#ffffff;">2</span></p>
<p align="right" style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:13px; -qt-block-indent:0; text-indent:0px; background-color:#ffffff;"><span style=" font-family:'Monaco,Consolas,Bitstream Vera Sans Mono,Courier New,Courier,monospace'; font-size:17px; color:#afafaf; background-color:#ffffff;">3</span></p>
<p align="right" style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:13px; -qt-block-indent:0; text-indent:0px; background-color:#ffffff;"><span style=" font-family:'Monaco,Consolas,Bitstream Vera Sans Mono,Courier New,Courier,monospace'; font-size:17px; color:#afafaf; background-color:#ffffff;">4</span></p></td>
<td bgcolor="#ffffff" style=" padding-left:0; padding-right:0; padding-top:0; padding-bottom:0;">
<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; background-color:#ffffff;"><span style=" font-family:'Monaco,Consolas,Bitstream Vera Sans Mono,Courier New,Courier,monospace'; font-size:17px; color:#000000;">delta = datetime.timedelta(days=365, hours=6, minutes=15, seconds=30)</span></p>
<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; background-color:#ffffff;"><span style=" font-family:'Monaco,Consolas,Bitstream Vera Sans Mono,Courier New,Courier,monospace'; font-size:17px; color:#222222; background-color:#ffffff;"> </span></p>
<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; background-color:#ffffff;"><span style=" font-family:'Monaco,Consolas,Bitstream Vera Sans Mono,Courier New,Courier,monospace'; font-size:17px; color:#000000;">print(delta.strftime('%j day(s) %H:%M:%S'))</span></p>
<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; background-color:#ffffff;"><span style=" font-family:'Monaco,Consolas,Bitstream Vera Sans Mono,Courier New,Courier,monospace'; font-size:17px; color:#000000;">print(delta.strftime('%m month(s) %d day(s) %H:%M:%S'))</span></p></td></tr></table>
<p style=" margin-top:0px; margin-bottom:20px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-family:'-apple-system,system-ui,BlinkMacSystemFont,Segoe UI,Helvetica,Arial,sans-serif,Apple Color Emoji,Segoe UI Emoji,Segoe UI Symbol'; font-size:17px; color:#222222;">В результате выполнения кода мы получим:</span></p>
<p style="-qt-paragraph-type:empty; margin-top:13px; margin-bottom:13px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; font-family:'-apple-system,system-ui,BlinkMacSystemFont,Segoe UI,Helvetica,Arial,sans-serif,Apple Color Emoji,Segoe UI Emoji,Segoe UI Symbol'; font-size:17px; color:#222222; background-color:#ffffff;"><br /></p>
<table border="0" style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px;" cellspacing="0" cellpadding="0">
<tr>
<td bgcolor="#ffffff" style=" padding-left:0; padding-right:0; padding-top:0; padding-bottom:0;">
<p align="right" style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:13px; -qt-block-indent:0; text-indent:0px; background-color:#ffffff;"><a name="highlighter_179652"></a><span style=" font-family:'Monaco,Consolas,Bitstream Vera Sans Mono,Courier New,Courier,monospace'; font-size:17px; color:#afafaf; background-color:#ffffff;">1</span></p>
<p align="right" style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:13px; -qt-block-indent:0; text-indent:0px; background-color:#ffffff;"><span style=" font-family:'Monaco,Consolas,Bitstream Vera Sans Mono,Courier New,Courier,monospace'; font-size:17px; color:#afafaf; background-color:#ffffff;">2</span></p></td>
<td bgcolor="#ffffff" style=" padding-left:0; padding-right:0; padding-top:0; padding-bottom:0;">
<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; background-color:#ffffff;"><span style=" font-family:'Monaco,Consolas,Bitstream Vera Sans Mono,Courier New,Courier,monospace'; font-size:17px; color:#000000;">365 day(s) 06:15:30</span></p>
<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; background-color:#ffffff;"><span style=" font-family:'Monaco,Consolas,Bitstream Vera Sans Mono,Courier New,Courier,monospace'; font-size:17px; color:#000000;">01 month(s) 01 day(s) 06:15:30</span></p></td></tr></table>
<p style=" margin-top:0px; margin-bottom:20px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-family:'-apple-system,system-ui,BlinkMacSystemFont,Segoe UI,Helvetica,Arial,sans-serif,Apple Color Emoji,Segoe UI Emoji,Segoe UI Symbol'; font-size:17px; color:#222222;">Перейдем к следующему способу вывода интервала времени без долей секунд — это использование метода str() объекта timedelta. Метод str() преобразует объект timedelta в строку, содержащую представление интервала времени в виде &quot;дни, часы:минуты:секунды&quot;. Таким образом, мы можем использовать метод str() для вывода интервала без долей секунд:</span></p>
<p style="-qt-paragraph-type:empty; margin-top:13px; margin-bottom:13px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; font-family:'-apple-system,system-ui,BlinkMacSystemFont,Segoe UI,Helvetica,Arial,sans-serif,Apple Color Emoji,Segoe UI Emoji,Segoe UI Symbol'; font-size:17px; color:#222222; background-color:#ffffff;"><br /></p>
<table border="0" style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px;" cellspacing="0" cellpadding="0">
<tr>
<td bgcolor="#ffffff" style=" padding-left:0; padding-right:0; padding-top:0; padding-bottom:0;">
<p align="right" style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:13px; -qt-block-indent:0; text-indent:0px; background-color:#ffffff;"><a name="highlighter_834810"></a><span style=" font-family:'Monaco,Consolas,Bitstream Vera Sans Mono,Courier New,Courier,monospace'; font-size:17px; color:#afafaf; background-color:#ffffff;">1</span></p>
<p align="right" style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:13px; -qt-block-indent:0; text-indent:0px; background-color:#ffffff;"><span style=" font-family:'Monaco,Consolas,Bitstream Vera Sans Mono,Courier New,Courier,monospace'; font-size:17px; color:#afafaf; background-color:#ffffff;">2</span></p>
<p align="right" style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:13px; -qt-block-indent:0; text-indent:0px; background-color:#ffffff;"><span style=" font-family:'Monaco,Consolas,Bitstream Vera Sans Mono,Courier New,Courier,monospace'; font-size:17px; color:#afafaf; background-color:#ffffff;">3</span></p></td>
<td bgcolor="#ffffff" style=" padding-left:0; padding-right:0; padding-top:0; padding-bottom:0;">
<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; background-color:#ffffff;"><span style=" font-family:'Monaco,Consolas,Bitstream Vera Sans Mono,Courier New,Courier,monospace'; font-size:17px; color:#000000;">delta = datetime.timedelta(days=365, hours=6, minutes=15, seconds=30)</span></p>
<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; background-color:#ffffff;"><span style=" font-family:'Monaco,Consolas,Bitstream Vera Sans Mono,Courier New,Courier,monospace'; font-size:17px; color:#222222; background-color:#ffffff;"> </span></p>
<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; background-color:#ffffff;"><span style=" font-family:'Monaco,Consolas,Bitstream Vera Sans Mono,Courier New,Courier,monospace'; font-size:17px; color:#000000;">print(str(delta).split('.')[0])</span></p></td></tr></table>
<p style=" margin-top:0px; margin-bottom:20px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-family:'-apple-system,system-ui,BlinkMacSystemFont,Segoe UI,Helvetica,Arial,sans-serif,Apple Color Emoji,Segoe UI Emoji,Segoe UI Symbol'; font-size:17px; color:#222222;">Результат выполнения кода будет следующим:</span></p>
<p style="-qt-paragraph-type:empty; margin-top:13px; margin-bottom:13px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; font-family:'-apple-system,system-ui,BlinkMacSystemFont,Segoe UI,Helvetica,Arial,sans-serif,Apple Color Emoji,Segoe UI Emoji,Segoe UI Symbol'; font-size:17px; color:#222222; background-color:#ffffff;"><br /></p>
<table border="0" style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px;" cellspacing="0" cellpadding="0">
<tr>
<td bgcolor="#ffffff" style=" padding-left:0; padding-right:0; padding-top:0; padding-bottom:0;">
<p align="right" style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:13px; -qt-block-indent:0; text-indent:0px; background-color:#ffffff;"><a name="highlighter_410386"></a><span style=" font-family:'Monaco,Consolas,Bitstream Vera Sans Mono,Courier New,Courier,monospace'; font-size:17px; color:#afafaf; background-color:#ffffff;">1</span></p></td>
<td bgcolor="#ffffff" style=" padding-left:0; padding-right:0; padding-top:0; padding-bottom:0;">
<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; background-color:#ffffff;"><span style=" font-family:'Monaco,Consolas,Bitstream Vera Sans Mono,Courier New,Courier,monospace'; font-size:17px; color:#000000;">365 days, 6:15:30</span></p></td></tr></table>
<p style=" margin-top:0px; margin-bottom:20px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-family:'-apple-system,system-ui,BlinkMacSystemFont,Segoe UI,Helvetica,Arial,sans-serif,Apple Color Emoji,Segoe UI Emoji,Segoe UI Symbol'; font-size:17px; color:#222222;">Здесь мы использовали метод split() для разбиения строки на две части и вывода только первой части без долей секунд.</span></p>
<p style=" margin-top:0px; margin-bottom:20px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-family:'-apple-system,system-ui,BlinkMacSystemFont,Segoe UI,Helvetica,Arial,sans-serif,Apple Color Emoji,Segoe UI Emoji,Segoe UI Symbol'; font-size:17px; color:#222222;">Также мы можем использовать форматирование строк для вывода интервала в нужном формате:</span></p>
<p style="-qt-paragraph-type:empty; margin-top:13px; margin-bottom:13px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; font-family:'-apple-system,system-ui,BlinkMacSystemFont,Segoe UI,Helvetica,Arial,sans-serif,Apple Color Emoji,Segoe UI Emoji,Segoe UI Symbol'; font-size:17px; color:#222222; background-color:#ffffff;"><br /></p>
<table border="0" style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px;" cellspacing="0" cellpadding="0">
<tr>
<td bgcolor="#ffffff" style=" padding-left:0; padding-right:0; padding-top:0; padding-bottom:0;">
<p align="right" style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:13px; -qt-block-indent:0; text-indent:0px; background-color:#ffffff;"><a name="highlighter_358039"></a><span style=" font-family:'Monaco,Consolas,Bitstream Vera Sans Mono,Courier New,Courier,monospace'; font-size:17px; color:#afafaf; background-color:#ffffff;">1</span></p>
<p align="right" style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:13px; -qt-block-indent:0; text-indent:0px; background-color:#ffffff;"><span style=" font-family:'Monaco,Consolas,Bitstream Vera Sans Mono,Courier New,Courier,monospace'; font-size:17px; color:#afafaf; background-color:#ffffff;">2</span></p>
<p align="right" style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:13px; -qt-block-indent:0; text-indent:0px; background-color:#ffffff;"><span style=" font-family:'Monaco,Consolas,Bitstream Vera Sans Mono,Courier New,Courier,monospace'; font-size:17px; color:#afafaf; background-color:#ffffff;">3</span></p></td>
<td bgcolor="#ffffff" style=" padding-left:0; padding-right:0; padding-top:0; padding-bottom:0;">
<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; background-color:#ffffff;"><span style=" font-family:'Monaco,Consolas,Bitstream Vera Sans Mono,Courier New,Courier,monospace'; font-size:17px; color:#000000;">delta = datetime.timedelta(days=365, hours=6, minutes=15, seconds=30)</span></p>
<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; background-color:#ffffff;"><span style=" font-family:'Monaco,Consolas,Bitstream Vera Sans Mono,Courier New,Courier,monospace'; font-size:17px; color:#222222; background-color:#ffffff;"> </span></p>
<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; background-color:#ffffff;"><span style=" font-family:'Monaco,Consolas,Bitstream Vera Sans Mono,Courier New,Courier,monospace'; font-size:17px; color:#000000;">print('{0.days} days, {0.hours:02}:{0.minutes:02}:{0.seconds:02}'.format(delta))</span></p></td></tr></table>
<p style=" margin-top:0px; margin-bottom:20px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-family:'-apple-system,system-ui,BlinkMacSystemFont,Segoe UI,Helvetica,Arial,sans-serif,Apple Color Emoji,Segoe UI Emoji,Segoe UI Symbol'; font-size:17px; color:#222222;">Здесь мы использовали метод format() для форматирования строки. В фигурных скобках мы указали индекс аргумента, переданного методу format(). Мы также использовали двоеточие и формат «%02d», чтобы выровнять значения от 0 до 9.</span></p>
<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-family:'-apple-system,system-ui,BlinkMacSystemFont,Segoe UI,Helvetica,Arial,sans-serif,Apple Color Emoji,Segoe UI Emoji,Segoe UI Symbol'; font-size:17px; color:#222222;">В этой статье мы рассмотрели два способа вывода интервала времени без долей секунд с помощью модуля datetime. Метод strftime() позволяет настраивать вывод интервала в соответствии с заданным форматом, а метод str() предоставляет готовый формат вывода «дни, часы:минуты:секунды». Вы можете выбрать тот метод, который лучше всего подходит для вашего проекта.</span></p></body></html>